home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / slip / cslip-2.6 / tip / libacu / v3451.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-03  |  4.1 KB  |  200 lines

  1. /*
  2.  * Copyright (c) 1983 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that: (1) source distributions retain this entire copyright
  7.  * notice and comment, and (2) distributions including binaries display
  8.  * the following acknowledgement:  ``This product includes software
  9.  * developed by the University of California, Berkeley and its contributors''
  10.  * in the documentation or other materials provided with the distribution
  11.  * and in all advertising materials mentioning features or use of this
  12.  * software. Neither the name of the University nor the names of its
  13.  * contributors may be used to endorse or promote products derived
  14.  * from this software without specific prior written permission.
  15.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  16.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  17.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18.  */
  19.  
  20. #ifndef lint
  21. static char sccsid[] = "@(#)v3451.c    5.1 (Berkeley) 4/30/85";
  22. #endif not lint
  23.  
  24. /*
  25.  * Routines for calling up on a Vadic 3451 Modem
  26.  */
  27. #include "tip.h"
  28.  
  29. static    jmp_buf Sjbuf;
  30.  
  31. static int expect(), prefix(), notin();
  32. static void alarmtr(), vawrite();
  33.  
  34. v3451_dialer(num, acu)
  35.     register char *num;
  36.     char *acu;
  37. {
  38.     int ok;
  39.     sigfunc_t (*func)();
  40.     int slow = number(value(BAUDRATE)) < 1200, rw = 2;
  41.     char phone[50];
  42. #ifdef ACULOG
  43.     char line[80];
  44. #endif
  45.  
  46.     /*
  47.      * Get in synch
  48.      */
  49.     vawrite("I\r", 1 + slow);
  50.     vawrite("I\r", 1 + slow);
  51.     vawrite("I\r", 1 + slow);
  52.     vawrite("\005\r", 2 + slow);
  53.     if (!expect("READY")) {
  54.         printf("can't synchronize with vadic 3451\n");
  55. #ifdef ACULOG
  56.         logent(value(HOST), num, "vadic", "can't synch up");
  57. #endif
  58.         return (0);
  59.     }
  60.     ioctl(FD, TIOCHPCL, 0);
  61.     sleep(1);
  62.     vawrite("D\r", 2 + slow);
  63.     if (!expect("NUMBER?")) {
  64.         printf("Vadic will not accept dial command\n");
  65. #ifdef ACULOG
  66.         logent(value(HOST), num, "vadic", "will not accept dial");
  67. #endif
  68.         return (0);
  69.     }
  70.     strcpy(phone, num);
  71.     strcat(phone, "\r");
  72.     vawrite(phone, 1 + slow);
  73.     if (!expect(phone)) {
  74.         printf("Vadic will not accept phone number\n");
  75. #ifdef ACULOG
  76.         logent(value(HOST), num, "vadic", "will not accept number");
  77. #endif
  78.         return (0);
  79.     }
  80.     func = signal(SIGINT,SIG_IGN);
  81.     /*
  82.      * You cannot interrupt the Vadic when its dialing;
  83.      * even dropping DTR does not work (definitely a
  84.      * brain damaged design).
  85.      */
  86.     vawrite("\r", 1 + slow);
  87.     vawrite("\r", 1 + slow);
  88.     if (!expect("DIALING:")) {
  89.         printf("Vadic failed to dial\n");
  90. #ifdef ACULOG
  91.         logent(value(HOST), num, "vadic", "failed to dial");
  92. #endif
  93.         return (0);
  94.     }
  95.     if (boolean(value(VERBOSE)))
  96.         printf("\ndialing...");
  97.     ok = expect("ON LINE");
  98.     signal(SIGINT, func);
  99.     if (!ok) {
  100.         printf("call failed\n");
  101. #ifdef ACULOG
  102.         logent(value(HOST), num, "vadic", "call failed");
  103. #endif
  104.         return (0);
  105.     }
  106.     ioctl(FD, TIOCFLUSH, &rw);
  107.     return (1);
  108. }
  109.  
  110. v3451_disconnect()
  111. {
  112.  
  113.     close(FD);
  114. }
  115.  
  116. v3451_abort()
  117. {
  118.  
  119.     close(FD);
  120. }
  121.  
  122. static void
  123. vawrite(cp, delay)
  124.     register char *cp;
  125.     int delay;
  126. {
  127.  
  128.     for (; *cp; sleep(delay), cp++)
  129.         write(FD, cp, 1);
  130. }
  131.  
  132. static int
  133. expect(cp)
  134.     register char *cp;
  135. {
  136.     char buf[300];
  137.     register char *rp = buf;
  138.     int timeout = 30, online = 0;
  139.  
  140.     if (strcmp(cp, "\"\"") == 0)
  141.         return (1);
  142.     *rp = 0;
  143.     /*
  144.      * If we are waiting for the Vadic to complete
  145.      * dialing and get a connection, allow more time
  146.      * Unfortunately, the Vadic times out 24 seconds after
  147.      * the last digit is dialed
  148.      */
  149.     online = strcmp(cp, "ON LINE") == 0;
  150.     if (online)
  151.         timeout = number(value(DIALTIMEOUT));
  152.     signal(SIGALRM, alarmtr);
  153.     if (setjmp(Sjbuf))
  154.         return (0);
  155.     alarm(timeout);
  156.     while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) {
  157.         if (online && notin("FAILED CALL", buf) == 0)
  158.             return (0);
  159.         if (read(FD, rp, 1) < 0) {
  160.             alarm(0);
  161.             return (0);
  162.         }
  163.         if (*rp &= 0177)
  164.             rp++;
  165.         *rp = '\0';
  166.     }
  167.     alarm(0);
  168.     return (1);
  169. }
  170.  
  171. static void
  172. alarmtr()
  173. {
  174.  
  175.     longjmp(Sjbuf, 1);
  176. }
  177.  
  178. static int
  179. notin(sh, lg)
  180.     char *sh, *lg;
  181. {
  182.  
  183.     for (; *lg; lg++)
  184.         if (prefix(sh, lg))
  185.             return (0);
  186.     return (1);
  187. }
  188.  
  189. static int
  190. prefix(s1, s2)
  191.     register char *s1, *s2;
  192. {
  193.     register char c;
  194.  
  195.     while ((c = *s1++) == *s2++)
  196.         if (c == '\0')
  197.             return (1);
  198.     return (c == '\0');
  199. }
  200.